const traverson = require("traverson");
const JsonHalAdapter = require("traverson-hal");
// register the traverson-hal plug-in for media type 'application/hal+json'
traverson.registerMediaType(JsonHalAdapter.mediaType, JsonHalAdapter);
export const get = (url, links) => {
  traverson
    .from(`http://${process.env.VUE_APP_BACKEND_URL}/${url}`)
    .jsonHal()
    .withTemplateParameters({ name: "traverson" })
    .withRequestOptions({
      headers: {
        Authorization: `Bearer ${window.localStorage.getItem("auth-token")}`
      }
    })
    .getResource(function(error, document, traversal) {
      if (error) {
        console.log(error);
      } else {
        console.log(document);
        traversal
          .continue()
          .follow(links)
          .getResource(function(err, secondResource) {
            if (err) {
              return done(err);
            }
            console.log(secondResource);
          });
      }
    });
};
